home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Programming / Source / Lyapunov / ColorMap.m < prev    next >
Encoding:
Text File  |  1992-07-31  |  1.2 KB  |  67 lines

  1.  
  2. /* Generated by Interface Builder */
  3.  
  4. #import "ColorMap.h"
  5. #import <stdio.h>
  6. #import <stdlib.h>
  7.  
  8. @implementation ColorMap
  9.  
  10. - init
  11. {
  12.     int i;
  13.     
  14.     [super init];
  15.     for(i=0; i < NUMCOLORS; i++) {
  16.         colormap[i].red = colormap[i].green = colormap[i].blue = i;
  17.     }
  18.     return self;
  19. }
  20.  
  21. - initFromFile:(const char *)name
  22. {
  23.     FILE *cmap;
  24.     char buf[255];        /* magic number */
  25.     int a,b,c,i,end;
  26.   
  27.     [self init];
  28.     cmap = fopen(name,"r");
  29.     if(!cmap) {
  30.         perror(name);
  31.     }
  32.  
  33.     i = 0;
  34.     while(!feof(cmap) && i <NUMCOLORS) {
  35.         fgets(buf,sizeof buf,cmap);
  36.         // unparseable lines are comments
  37.         // as is anything after the <r g b> value on a single line
  38.         // per Fractint 15.1 standard
  39.         if(sscanf(buf,"%d %d %d",&a,&b,&c) == 3) {
  40.             colormap[i].red = a;
  41.             colormap[i].green = b;
  42.             colormap[i].blue = c;
  43.             i++;
  44.         }
  45.     }
  46.     fclose(cmap);
  47.     end = i;
  48.     while (i<NUMCOLORS) {    // repeat map until full.
  49.         colormap[i].red = colormap[i - end].red;
  50.         colormap[i].green = colormap[i - end].green;
  51.         colormap[i].blue = colormap[i - end].blue;
  52.         i++;
  53.     }
  54.     return self;
  55. }
  56.  
  57. - colorFor:(int)ref :(int *)r :(int *)g :(int *)b
  58. {
  59.     *r = colormap[ref].red;
  60.     *g = colormap[ref].green;
  61.     *b = colormap[ref].blue;
  62.     return self;
  63. }
  64.  
  65.  
  66. @end
  67.